package com.haoran.dwz.domain.entities;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.springframework.format.annotation.DateTimeFormat;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

@Entity
@Table(name = "t_url_recycle_bin")
@ApiModel("短链接回收站")
public class URLRecycleBin extends PaginationEntity {
	@Id
	@GeneratedValue
	private Long id;

	@ApiModelProperty(value = "短链接", required = true)
	@Column(unique = false, nullable = false)
	private String shortUrl;

	@ApiModelProperty(value = "短链接对应的原始链接", required = true)
	@Column(unique = false, nullable = false)
	private String url;

	@ApiModelProperty(value = "删除人", required = true)
	@Column()
	private String user;

	@ApiModelProperty(value = "短链接创建时间", example = "yyyy-MM-dd HH:mm:ss")
	@Column(name = "create_time")
	@Temporal(TemporalType.TIMESTAMP)
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	private Date createTime;

	@ApiModelProperty(value = "短链接失效时间", example = "yyyy-MM-dd HH:mm:ss")
	@Column(name = "expire_time")
	@Temporal(TemporalType.TIMESTAMP)
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	private Date expireTime;

	@ApiModelProperty(value = "短链接最后一次使用时间", example = "yyyy-MM-dd HH:mm:ss")
	@Column(name = "last_used_time")
	@Temporal(TemporalType.TIMESTAMP)
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	private Date lastUsedTime;

	@ApiModelProperty(value = "短链接删除时间", example = "yyyy-MM-dd HH:mm:ss")
	@Column(name = "delete_time")
	@Temporal(TemporalType.TIMESTAMP)
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	private Date deleteTime = new Date();

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getUser() {
		return user;
	}

	public void setUser(String user) {
		this.user = user;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public Date getExpireTime() {
		return expireTime;
	}

	public void setExpireTime(Date expireTime) {
		this.expireTime = expireTime;
	}

	public Date getLastUsedTime() {
		return lastUsedTime;
	}

	public void setLastUsedTime(Date lastUsedTime) {
		this.lastUsedTime = lastUsedTime;
	}

	public Date getDeleteTime() {
		return deleteTime;
	}

	public String getShortUrl() {
		return shortUrl;
	}

	public void setShortUrl(String shortUrl) {
		this.shortUrl = shortUrl;
	}

	public void setDeleteTime(Date deleteTime) {
		this.deleteTime = deleteTime;
	}

	public static class Builder {

		/**
		 * 构造器
		 * 
		 * @param shortURLInfo
		 *            删除的短链接信息
		 * @param user
		 *            删除人
		 * @return
		 */
		public static URLRecycleBin builder(ShortURL shortURLInfo, String user) {
			URLRecycleBin entity = new URLRecycleBin();
			entity.setShortUrl(shortURLInfo.getDwz());
			entity.setUrl(shortURLInfo.getUrl());
			entity.setUser(user);
			entity.setLastUsedTime(shortURLInfo.getLastUsedTime());
			entity.setCreateTime(shortURLInfo.getCreateTime());
			entity.setExpireTime(shortURLInfo.getExpireTime());
			return entity;
		}
	}
}
